<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;
use think\Request;

class Zhuanyecidian extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = 'default';

    public function index()
    {
		$this->view->assign('title', __('专业词典'));
		
		$banner=Db::name('banner')->where([
			'type_data'=>0,
			'bannertype_id'=>19
		])->select();
		
		$this->assign('banner',$banner);
		
		$hangyexinxi_type2=Db::name('hangyexinxitype')->where(['id'=>['>',1],'show_switch'=>1])->order('weigh desc')->limit(3)->select();
		foreach($hangyexinxi_type2 as $k=>$v){
			$hangyexinxi_type2[$k]['list']=Db::name('hangyexinxi')->where(['type_id'=>$v['id']])->order('weigh desc')->limit(4)->select();
		}
		$this->assign('hangyexinxi_type2',$hangyexinxi_type2);
		
		
		
        return $this->view->fetch();
    }
	
	public function fanyi(){
		$this->view->assign('title', __('专业词典'));
		$banner=Db::name('banner')->where([
			'type_data'=>0,
			'bannertype_id'=>19
		])->select();
		
		$this->assign('banner',$banner);
		
		$hangyexinxi_type2=Db::name('hangyexinxitype')->where(['id'=>['>',1],'show_switch'=>1])->order('weigh desc')->limit(3)->select();
		foreach($hangyexinxi_type2 as $k=>$v){
			$hangyexinxi_type2[$k]['list']=Db::name('hangyexinxi')->where(['type_id'=>$v['id']])->order('weigh desc')->limit(4)->select();
		}
		$this->assign('hangyexinxi_type2',$hangyexinxi_type2);
		
		
		$keyword=$this->request->param('keyword/s','');
		$rs=Db::name('cihui')->where(['word'=>$keyword])->find();
		Db::name('cihui')->where(['id'=>$rs['id']])->setInc('weigh');
		
		$this->assign('rs',$rs);
		$this->assign('keyword',$keyword);
		$this->assign('empty','<div class="empty">
					<div>
						<img src="/mobile/img/ico_empty.png" >
						<p>没有查询到对应内容</p>
					</div>
				</div>');
		return $this->view->fetch();
	}
    
    public function ajax_fanyi(Request $request){
        if($request->isAjax()){
            $keyword=$this->request->param('keyword/s','');
    		$rs=Db::name('cihui')->where(['word'=>$keyword])->find();
    		if(is_null($rs)){
    		    return json(['code'=>0,'msg'=>'没有查询到对应内容']);
    		}else{
    		    Db::name('cihui')->where(['id'=>$rs['id']])->setInc('weigh');
    		    return json(['code'=>1,'data'=>$rs]);
    		}
        }
        
		
		
    }
}
